package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.OutStoreDTO;
import net.wanho.po.OutStore;
import net.wanho.service.OutStoreService;
import net.wanho.mapper.OutStoreMapper;
import net.wanho.vo.OutStoreVo;
import net.wanho.vo.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
* @author 王洋
* @description 针对表【out_store(出库单表)】的数据库操作Service实现
* @createDate 2024-09-03 17:43:36
*/
@Service
public class OutStoreServiceImpl extends ServiceImpl<OutStoreMapper, OutStore>
    implements OutStoreService{

    @Override
    public PageInfo<OutStoreVo> outStorePageList(Integer pageNum, Integer pageSize, OutStoreDTO outStoreDTO) {
        Page<OutStoreVo> page = new Page<>(pageNum,pageSize);
        QueryWrapper<OutStoreVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(ObjectUtils.isNotEmpty(outStoreDTO.getProductName()),"product_name",outStoreDTO.getProductName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(outStoreDTO.getStoreId()),"s.store_id",outStoreDTO.getStoreId());
        queryWrapper.between(ObjectUtils.isNotEmpty(outStoreDTO.getStartTime())&& ObjectUtils.isNotEmpty(outStoreDTO.getEndTime()),"o.create_time",outStoreDTO.getStartTime(),outStoreDTO.getEndTime());
        queryWrapper.ge(!ObjectUtils.isEmpty(outStoreDTO.getStartTime()), "o.create_time", outStoreDTO.getStartTime());
        queryWrapper.le(!ObjectUtils.isEmpty(outStoreDTO.getEndTime()), "o.create_time", outStoreDTO.getEndTime());
        queryWrapper.eq(ObjectUtils.isNotEmpty(outStoreDTO.getIsOut()),"o.is_out",outStoreDTO.getIsOut());
        this.baseMapper.selectByPage(page,queryWrapper);
        PageInfo<OutStoreVo> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setLimitIndex((page.getCurrent()-1)*page.getSize());
        pageInfo.setResultList(page.getRecords());
        return pageInfo;

    }
}




